using System;
using System.Windows.Input;

namespace KharaPos.Helpers
{
    public class DelegateCommand : ICommand
    {

        public DelegateCommand(Action<object>execute)
            :this(execute,null)
        {
           
        }

        private DelegateCommand(Action<object> execute, Func<object,bool> canExecute)
        {
            ExecuteInvoked = execute;
            CanExecuteInvoked = canExecute;
        }

        public Func<object, bool> CanExecuteInvoked
        {
            get; set;
        }

        public Action<object> ExecuteInvoked
        {
            get; set;
        }

        public bool CanExecute(object parameter)
        {
            if (CanExecuteInvoked!=null)
            {
                CanExecuteInvoked(parameter);
            }
            return true;
        }

        public void Execute(object parameter)
        {
            if(ExecuteInvoked!=null)
            {
                ExecuteInvoked(parameter);
            }
        }

        public event EventHandler CanExecuteChanged;
    }
}